package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.service.AdminUserService;
import com.cskaoyan.market.service.impl.AdminUserServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName AdminUserController
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/7/22 11:20
 * @Version V1.0
 **/
@WebServlet("/admin/user/*")
public class AdminUserController extends HttpServlet {

    AdminUserService adminUserService = new AdminUserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String requestURI = req.getRequestURI();
        String op = requestURI.replace(req.getContextPath() + "/admin/user/", "");
        if("list".equals(op)){
            list(req, resp);
        }
    }

    //查询列表数据
    private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        String sort = req.getParameter("sort");
        String order = req.getParameter("order");
        String username = req.getParameter("username");
        String mobile = req.getParameter("mobile");
        List<MarketUser> userList = adminUserService.list(page, limit, sort, order,username, mobile);
        //对于分页查询的这些接口，那么我们需要调用oKlIST方法
        Object o = ResponseUtil.okList(userList);
        resp.getWriter().println(JacksonUtil.writeValueAsString(o));
    }
}
